package com.dayu.sale.controller;

import java.util.List;

import com.dayu.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.sale.domain.DyRefundInfo;
import com.dayu.sale.service.IDyRefundInfoService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 版本3 --- 退单信息Controller
 *
 * @author HK
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/sale/refund")
public class DyRefundInfoController extends BaseController
{
    @Resource
    private IDyRefundInfoService dyRefundInfoService;

    /**
     * 查询版本3 --- 退单信息列表
     */
    @PreAuthorize("@ss.hasPermi('sale:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(DyRefundInfo dyRefundInfo)
    {
        startPage();
        List<DyRefundInfo> list = dyRefundInfoService.selectDyRefundInfoList(dyRefundInfo);
        return getDataTable(list);
    }

    /**
     * 导出版本3 --- 退单信息列表
     */
    @PreAuthorize("@ss.hasPermi('sale:refund:export')")
    @Log(title = "版本3 --- 退单信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DyRefundInfo dyRefundInfo)
    {
        List<DyRefundInfo> list = dyRefundInfoService.selectDyRefundInfoList(dyRefundInfo);
        ExcelUtil<DyRefundInfo> util = new ExcelUtil<DyRefundInfo>(DyRefundInfo.class);
        return util.exportExcel(list, "refund");
    }

    /**
     * 获取版本3 --- 退单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:refund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dyRefundInfoService.selectDyRefundInfoById(id));
    }

    /**
     * 新增版本3 --- 退单信息
     */
    @PreAuthorize("@ss.hasPermi('sale:refund:add')")
    @Log(title = "版本3 --- 退单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DyRefundInfo dyRefundInfo)
    {
        return toAjax(dyRefundInfoService.insertDyRefundInfo(dyRefundInfo));
    }

    @Log(title = "账单通过", businessType = BusinessType.UPDATE)
    @PutMapping("/pass")
    @PreAuthorize("@ss.hasPermi('sale:refund:pass')")
    @RepeatSubmit
    public AjaxResult pass(@RequestParam("id")Long id, @RequestParam(name = "remark", required = false)String remark) {
        return toAjax(dyRefundInfoService.refundPass(id, remark));
    }

    @Log(title = "账单不通过", businessType = BusinessType.UPDATE)
    @PutMapping("/noPass")
    @PreAuthorize("@ss.hasPermi('sale:refund:noPass')")
    @RepeatSubmit
    public AjaxResult noPass(@RequestParam(name ="id")Long id, @RequestParam(name = "remark", required = false)String remark) {
        return toAjax(dyRefundInfoService.refundNoPass(id, remark));
    }
}
